import Vue from 'vue';
import Router from 'vue-router';
import Layout from './views/Layout/Index.vue';
import jwt_decode from 'jwt-decode';

Vue.use(Router);

/**
 * hidden: true                   如果hidden为true则在左侧菜单栏展示，否则不显示
 * name:'router-name'             路由名称，必须填写
 * meta : {
    title: 'title'               对应路由在左侧菜单栏的标题名称
    icon: 'icon-class'           对应路由在左侧菜单栏的图标样式，样式使用fontawesome图标库
  }
 **/

export const asyncRouterMap = [
  {
    path: '/',
    name: 'dashboard',
    component: Layout,
    hidden: true,
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        meta: { title: '首页', icon: 'fa fa-home' },
        component: () => import('@/views/Home.vue')
      }
    ]
  },
  {
    path: '/supplierManage',
    name: 'supplierManage',
    component: Layout,
    hidden: true,
    meta: { title: '供应商管理', icon: 'fa fa-th-large' },
    redirect: '/supplierList',
    children:[
      {
        path: '/supplierList',
        name: 'supplierList',
        meta: { title: '供应商管理', icon: 'fa fa-user-circle'},
        component: () => import('@/views/supplierManage/supplierList.vue'),
      },
    ]
  },
  {
    path: '/cashier',
    name: 'cashier',
    component: Layout,
    hidden: true,
    meta: { title: '收银台管理', icon: 'fa fa-th-large' },
    redirect: '/cashier',
    children:[
      {
        path: '/cashierOrder',
        name: 'cashierOrder',
        meta: { title: '收银台流水', icon: 'fa fa-user-circle'},
        component: () => import('@/views/businessManage/cashier/shopCashier.vue'),
      },
    ]
  },
  {
    path: '/businessManage',
    name: 'businessManage',
    component: Layout,
    hidden: true,
    meta: { title: '商家管理', icon: 'fa fa-th-large' },
    redirect: '/businessList',
    children:[
      {
        path: '/businessList',
        name: 'businessList',
        meta: { title: '商家列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/businessManage/businessList/businessList.vue'),
        children:[
          {
            path: '/businessList/add',
            name: 'businessAdd',
            meta: { title: '新建商家', icon: 'fa fa-user-plus' },
            component: () => import('@/views/businessManage/businessList/Add.vue'),
          },
          {
            path: '/businessList/edit',
            name: 'businessEdit',
            meta: { title: '编辑商家', icon: 'fa fa-user-plus'},
            component: () => import('@/views/businessManage/businessList/Edit.vue'),
          },
          {
            path: '/businessList/cashier',
            name: 'cashierList',
            meta: { title: '收银台明细', icon: 'fa fa-user-plus'},
            component: () => import('@/views/businessManage/cashier/list.vue'),
          }
        ]
      },
      {
        path: '/storeList',
        name: 'storeList',
        meta: { title: '门店列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/businessManage/storeList/storeList.vue'),
        children:[
          {
            path: '/storeList/add',
            name: 'storeAdd',
            meta: { title: '新建门店', icon: 'fa fa-user-plus' },
            component: () => import('@/views/businessManage/storeList/Add.vue'),
          },
          {
            path: '/storeList/edit',
            name: 'storeEdit',
            meta: { title: '编辑门店', icon: 'fa fa-user-plus'},
            component: () => import('@/views/businessManage/storeList/Edit.vue'),
          }
        ]
      },
      {
        path: '/writeOffList',
        name: 'writeOffList',
        meta: { title: '核销员管理', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/businessManage/writeOffList/writeOffList.vue'),
      },
      {
        path: '/businessTypeList',
        name: 'businessTypeList',
        meta: { title: '商家类型', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/businessManage/businessTypeList/businessTypeList.vue'),
      },
    ]
  },
  {
    path: '/gooodsManage',
    name: 'gooodsManage',
    component: Layout,
    hidden: true,
    meta: { title: '商品管理', icon: 'fa fa-th-large' },
    redirect: '/goodsList',
    children:[
      {
        path: '/kindList',
        name: 'kindList',
        meta: { title: '分类管理', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/gooodsManage/kindList/kindList.vue'),

      },
      {
        path: '/labelList',
        name: 'labelList',
        meta: { title: '标签管理', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/gooodsManage/labelList/labelList.vue'),
      },
      {
        path: '/goodsList',
        name: 'goodsList',
        meta: { title: '商品列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/gooodsManage/goodsList/goodsList.vue'),
        children:[
          {
            path: '/goodsList/add',
            name: 'goodsAdd',
            meta: { title: '新建商品', icon: 'fa fa-user-plus' },
            component: () => import('@/views/gooodsManage/goodsList/Add.vue'),
          },
          {
            path: '/goodsList/edit',
            name: 'goodsEdit',
            meta: { title: '编辑商品', icon: 'fa fa-user-plus'},
            component: () => import('@/views/gooodsManage/goodsList/Edit.vue'),
          },{
            path: '/goodsList/goodsDetail',
            name: 'goodsDetail',
            meta: { title: '商品详情', icon: 'fa fa-user-plus'},
            component: () => import('@/views/gooodsManage/goodsList/goodsDetail.vue'),
          }
        ]
      },
      {
        path: '/freightList',
        name: 'freightList',
        meta: { title: '运费模板', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/gooodsManage/freightList/freightList.vue'),
      },
      {
        path: '/templateList',
        name: 'templateList',
        meta: { title: '留言模板', icon: 'fa fa-user-circle' },
        component: () => import('@/views/gooodsManage/commentsTemplate/templateList.vue'),
        children:[
          {
            path: '/templateList/newEditor',
            name: 'newEditor',
            meta: { title: '留言模板', icon: 'fa fa-user-plus' },
            component: () => import('@/views/gooodsManage/commentsTemplate/newEditor.vue'),
          },
        ]
      },
    ]
  },
  {
    path: '/channelManage',
    name: 'channelManage',
    component: Layout,
    hidden: true,
    meta: { title: '渠道管理', icon: 'fa fa-th-large' },
    redirect: '/channelList',
    children:[
      {
        path: '/channelList',
        name: 'channelList',
        meta: { title: '渠道列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/channelManage/channelList/channelList.vue'),
        children:[
          {
            path: '/channelList/add',
            name: 'channelAdd',
            meta: { title: '新建渠道', icon: 'fa fa-user-plus' },
            component: () => import('@/views/channelManage/channelList/Add.vue'),
          },
          {
            path: '/channelList/edit',
            name: 'channelEdit',
            meta: { title: '编辑渠道', icon: 'fa fa-user-plus'},
            component: () => import('@/views/channelManage/channelList/Edit.vue'),
          }
        ]
      },
      {
        path: '/specialSet',
        name: 'specialSet',
        meta: { title: '特殊商品设置', icon: 'fa fa-user-plus'},
        component: () => import('@/views/channelManage/channelList/specialSet.vue'),
      },
      {
        path: '/channelLog',
        name: 'channelLog',
        meta: { title: '调用日志', icon: 'fa fa-user-plus'},
        component: () => import('@/views/channelManage/channelList/channelLog.vue'),
      },
      {
        path: '/channelKindList',
        name: 'channelKindList',
        meta: { title: '渠道分类', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/channelManage/channelKindList/channelKindList.vue'),

      },

    ]
  },
  {
    path: '/company',
    name: 'company',
    component: Layout,
    hidden: true,
    meta: { title: '企业管理', icon: 'fa fa-th-large' },
    redirect: '/company',
    children:[
      {
        path: '/companyList',
        name: 'companyList',
        meta: { title: '企业列表', icon: 'fa fa-user-circle' },
        component: () => import('@/views/company/index.vue'),
      },
      {
        path: '/ruleList',
        name: 'ruleList',
        meta: { title: '充送规则', icon: 'fa fa-user-circle' },
        component: () => import('@/views/company/rules.vue'),
      },
      {
        path: '/companyRules',  // 企业端
        name: 'companyRules',
        meta: { title: '充送规则', icon: 'fa fa-user-circle' },
        component: () => import('@/views/companyManage/rules.vue'),
      }
    ]
  },
  {
    path: '/orderManage',
    name: 'orderManage',
    component: Layout,
    hidden: true,
    meta: { title: '订单管理', icon: 'fa fa-th-large' },
    redirect: '/orderList',
    children:[
      {
        path: '/orderList',
        name: 'orderList',
        meta: { title: '订单列表', icon: 'fa fa-user-circle' },
        component: () => import('@/views/orderManage/orderList.vue'),
        children:[
          {
            path: '/orderList/orderDetail',
            name: 'orderDetail',
            meta: { title: '订单详情', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/orderManage/orderDetail.vue'),
          }
        ]
      },
      {
        path: '/pastOrderList',
        name: 'pastOrderList',
        meta: { title: '发货订单', icon: 'fa fa-user-circle' },
        component: () => import('@/views/orderManage/pastOrderList.vue'),
        children:[
          {
            path: '/pastOrderList/orderDetail',
            name: 'pastOrderDetail',
            meta: { title: '订单详情', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/orderManage/orderDetail.vue'),
          }
        ]
      },
      {
        path: '/refundOrderList',
        name: 'refundOrderList',
        meta: { title: '退款订单', icon: 'fa fa-user-circle' },
        component: () => import('@/views/orderManage/refundOrderList.vue'),
        children:[
          {
            path: '/refundOrderList/orderDetail',
            name: 'refundOrderDetail',
            meta: { title: '订单详情', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/orderManage/orderDetail.vue'),
          }
        ]
      },
    ]
  },
  {
    path: '/userManage',
    name: 'userManage',
    component: Layout,
    hidden: true,
    meta: { title: '用户管理', icon: 'fa fa-th-large' },
    redirect: '/userList',
    children:[
      {
        path: '/userList',
        name: 'userList',
        meta: { title: '用户列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/userManage/userList.vue'),

      },
    ]
  },
  {
    path: '/codeManage',
    name: 'codeManage',
    component: Layout,
    hidden: true,
    meta: { title: '核销码管理', icon: 'fa fa-th-large' },
    redirect: '/codeList',
    children:[
      {
        path: '/codeList',
        name: 'codeList',
        meta: { title: '核销码列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/codeManage/codeList.vue'),

      },
    ]
  },
  {
    path: '/writeManage',
    name: 'writeManage',
    component: Layout,
    hidden: true,
    meta: { title: '核销管理', icon: 'fa fa-th-large' },
    redirect: '/recordList',
    children:[
      {
        path: '/recordList',
        name: 'recordList',
        meta: { title: '核销记录', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/writeManage/recordList.vue'),
      },
      {
        path: '/quickWrite',
        name: 'quickWrite',
        meta: { title: '快捷核销', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/writeManage/quickWrite.vue'),
      }
    ]
  },
  {
    path: '/settlementManage',
    name: 'settlementManage',
    component: Layout,
    hidden: true,
    meta: { title: '结算管理', icon: 'fa fa-th-large' },
    redirect: '/businessSettlement',
    children:[
      {
        path: '/businessSettlement',
        name: 'businessSettlement',
        meta: { title: '商家结算管理', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/settlementManage/businessSettlement/businessSettlement.vue'),
        children:[
          {
            path: '/businessSettlement/businessDetail',
            name: 'businessDetail',
            meta: { title: '商品结算明细', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/settlementManage/businessSettlement/businessDetail.vue'),
          },{
            path: '/businessSettlement/cashierDetail',
            name: 'cashierDetail',
            meta: { title: '收银台结算明细', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/settlementManage/businessSettlement/cashierDetail.vue'),
          }
        ]
      },
      {
        path: '/businessSettlement/businessExamine',
        name: 'businessExamine',
        meta: { title: '商家结算审核', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/settlementManage/businessSettlement/businessExamine.vue'),
      },
      {
        path: '/channelSettlement',
        name: 'channelSettlement',
        meta: { title: '渠道结算管理', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/settlementManage/channelSettlement/channelSettlement.vue'),
        children:[
          {
            path: '/channelSettlement/channelDetail',
            name: 'channelDetail',
            meta: { title: '结算明细', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/settlementManage/channelSettlement/channelDetail.vue'),
          }
        ]
      },
      {
        path: '/channelSettlement/channelExamine',
        name: 'channelExamine',
        meta: { title: '渠道结算审核', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/settlementManage/channelSettlement/channelExamine.vue'),
      },
    ]
  },
  {
    path: '/storageManage',
    name: 'storageManage',
    component: Layout,
    hidden: true,
    meta: { title: '储值管理', icon: 'fa fa-th-large' },
    redirect: '/storageList',
    children:[
      {
        path: '/storageList',
        name: 'storageList',
        meta: { title: '储值列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/storageManage/storageList.vue'),
        children:[
          {
            path: '/storageList/storageDetail',
            name: 'storageDetail',
            meta: { title: '储值流水', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/storageManage/storageDetail.vue'),
          }
        ]
      }
    ]
  },
  {
    path: '/systemManage',
    name: 'systemManage',
    component: Layout,
    hidden: true,
    meta: { title: '权限管理', icon: 'fa fa-th-large' },
    redirect: '/systemList',
    children:[
      {
        path: '/systemList',
        name: 'systemList',
        meta: { title: '权限', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/systemManage/systemList.vue'),
      },
      {
        path: '/systemGroupList',
        name: 'systemGroupList',
        meta: { title: '权限组管理', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/systemManage/systemGroupList.vue'),
        children:[
          {
            path: '/systemList/add',
            name: 'systemAdd',
            meta: { title: '新建权限组', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/systemManage/Add.vue'),
          },{
            path: '/systemList/edit',
            name: 'systemEdit',
            meta: { title: '编辑权限组', icon: 'fa fa-user-plus', roles: ['admin'] },
            component: () => import('@/views/systemManage/Edit.vue'),
          }
        ]
      },
      {
        path: '/AuthorityModule',
        name: 'authorityModule',
        meta: { title: '权限模块', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/systemManage/AuthorityModule.vue'),
      }
    ]
  },
  {
    path: '/adminManage',
    name: 'adminManage',
    component: Layout,
    hidden: true,
    meta: { title: '权限管理', icon: 'fa fa-th-large' },
    redirect: '/adminList',
    children:[
      {
        path: '/adminList',
        name: 'adminList',
        meta: { title: '权限', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/adminManage/adminList.vue'),
      },
    ]
  },
  {
    path: '/operationManage',
    name: 'operationManage',
    component: Layout,
    hidden: true,
    meta: { title: '操作日志', icon: 'fa fa-th-large' },
    redirect: '/operationList',
    children:[
      {
        path: '/operationList',
        name: 'operationList',
        meta: { title: '日志列表', icon: 'fa fa-user-circle' },
        // meta: { title: '广告管理', icon: 'fa fa-user-circle', roles: ['admin'] },
        component: () => import('@/views/operationManage/operationList.vue'),

      },
    ]
  },
  {
    path: '/enterpriseStyleManagement',
    name: 'enterpriseStyleManagement',
    component: Layout,
    hidden: true,
    meta: { title: '企业端样式管理', icon: 'fa fa-th-large' },
    redirect: '/frontPageStyle',
    children:[
      {
        path: '/frontPageStyle',
        name: 'frontPageStyle',
        meta: { title: '首页样式', icon: 'fa fa-user-circle' },
        component: () => import('@/views/enterpriseStyleManagement/frontPageStyle.vue'),
      }
    ]
  },
  {
    path: '/activityManagement',
    name: 'activityManagement',
    component: Layout,
    hidden: true,
    meta: {title: '福利管理', icon: 'fa fa-th-large'},
    redirect: '/activityList',
    children: [
      {
        path: '/activityList',
        name: 'activityList',
        meta: {title: '发放记录', icon: 'fa fa-user-circle'},
        component: () => import('@/views/companyManage/activity/activityList.vue'),
        children: [
          {
            path: '/activityList/activityDetail',
            name: 'activityDetail',
            meta: {title: '福利明细', icon: 'fa fa-user-plus' ,roles: ['admin']},
            component: () => import('@/views/companyManage/activity/activityDetail.vue'),
          }
        ]
      }
    ]
  },
  {
    path: '/activityManagement',
    name: 'activityManagement',
    component: Layout,
    hidden: true,
    meta: {title: '福利管理', icon: 'fa fa-th-large'},
    redirect: '/activityList',
    children: [
      {
        path: '/activityList',
        name: 'activityList',
        meta: {title: '发放记录', icon: 'fa fa-user-circle'},
        component: () => import('@/views/companyManage/activity/activityList.vue'),
        children: [
          {
            path: '/activityList/activityDetail',
            name: 'activityDetail',
            meta: {title: '福利明细', icon: 'fa fa-user-plus' ,roles: ['admin']},
            component: () => import('@/views/companyManage/activity/activityDetail.vue'),
          }
        ]
      }
    ]
  },
  {
    path: '/staffManagement',
    name: 'staffManagement',
    component: Layout,
    hidden: true,
    meta: { title: '员工管理', icon: 'fa fa-th-large' },
    redirect: '/departmentList',
    children:[
      {
        path: '/departmentList',
        name: 'departmentList',
        meta: { title: '部门管理', icon: 'fa fa-user-circle' },
        component: () => import('@/views/staffManagement/departmentList.vue')
      },
      {
        path: '/employeeList',
        name: 'employeeList',
        meta: { title: '员工管理', icon: 'fa fa-user-circle' },
        component: () => import('@/views/staffManagement/employee/employeeList.vue'),
        children: [
          {
            path: '/employeeList/employeeDetail',
            name: 'employeeDetail',
            meta: {title: '储值明细', icon: 'fa fa-user-plus' ,roles: ['admin']},
            component: () => import('@/views/staffManagement/employee/employeeDetail.vue'),
          }
        ]
      },
      {
        path: '/employeeAmountList',
        name: 'employeeAmountList',
        meta: { title: '储值申请列表', icon: 'fa fa-user-circle' },
        component: () => import('@/views/companyManage/personnelAmount/personnelAmountList.vue')
      }
    ]
  },
  {
    path: '/invoiceInformation',
    name: 'invoiceInformation',
    component: Layout,
    hidden: true,
    meta: { title: '发票信息', icon: 'fa fa-th-large' },
    redirect: '/invoiceInformation',
    children:[
      {
        path: '/invoiceInformation',
        name: 'invoiceInformation',
        meta: { title: '发票信息', icon: 'fa fa-user-circle'},
        component: () => import('@/views/controlOverInvoices/invoiceInformation.vue'),
      },
    ]
  },
  {
    path: '/invoice',
    name: 'invoice',
    component: Layout,
    hidden: true,
    meta: { title: '发票管理', icon: 'fa fa-th-large' },
    redirect: '/invoice',
    children:[
      {
        path: '/invoiceApply',
        name: 'invoiceApply',
        meta: { title: '发票审核', icon: 'fa fa-user-circle'},
        component: () => import('@/views/invoice/index.vue'),
      },{
        path: '/canApplyList',
        name: 'canApplyList',
        meta: { title: '发票审核', icon: 'fa fa-user-circle'},
        component: () => import('@/views/invoice/merchant/canApplyList.vue'),
      }
      // {
      //   path: '/shouldReceiveList',
      //   name: 'shouldReceiveList',
      //   meta: { title: '应收票据', icon: 'fa fa-user-circle'},
      //   component: () => import('@/views/invoice/shouldReceiveList.vue'),
      // },
    ]
  },
  // {
  //   path: '/chargingRules',
  //   name: 'chargingRules',
  //   hidden: false,
  //   meta: { title: '充送规则' },
  //   component: () => import('@/views/chargingRules/chargingRules.vue')
  // },
  {
    path: '/articleManagement',
    name: 'articleManagement',
    component: Layout,
    hidden: true,
    meta: { title: '文章管理', icon: 'fa fa-th-large' },
    redirect: '/articleList',
    children:[
      {
        path: '/articleList',
        name: 'articleList',
        meta: { title: '文章列表', icon: 'fa fa-user-circle'},
        component: () => import('@/views/articleManagement/articleList.vue'),
      },
      {
        path: '/articleDetails',
        name: 'articleDetails',
        meta: { title: '文章详情', icon: 'fa fa-user-circle'},
        component: () => import('@/views/articleManagement/articleDetails.vue'),
      }
    ]
  },
  {
    path: '/404',
    name: '404',
    hidden: false,
    meta: { title: '404' },
    component: () => import('@/views/404.vue')
  },
  {
    path: '*',
    meta: { title: '*' },
    hidden: false,
    redirect: '/404'
  },
  {
    path: '/login',
    name: 'login',
    hidden: false,
    meta: { title: '系统登录' },
    component: () => import('@/views/Login/Login.vue')
  },
  {
    path: '/password',
    name: 'password',
    hidden: false,
    meta: { title: '找回密码' },
    component: () => import('@/views/Login/Password.vue')
  }
];


const router: any = new Router({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: asyncRouterMap
});

router.beforeEach((to: any, from: any, next: any) => {
  // next();
  const isLogin = localStorage.tsToken ? true : false;

  if (to.path == '/login' || to.path == '/password') {
    next();
  } else {
    if (!isLogin) {
      next('/login');
    }else{
      next();
    }
  }
  // if (to.path == '/login' || to.path == '/password') {
  //   next();
  // } else {
  //   if (isLogin) {
  //     const decoded: any = jwt_decode(localStorage.tsToken);
  //     const { key } = decoded;
  //     // 权限判断
  //     if (hasPermission(key, to)) {
  //       next();
  //     } else {
  //       next('/404'); // 没有权限进入
  //     }
  //   } else {
  //     next('/login');
  //   }
  // }
});

/**
 * 判断是否有权限
 * @param roles 当前角色
 * @param route 当前路由对象
 * */
function hasPermission(roles: string, route: any) {
  if (route.meta && route.meta.roles) {
    // 如果meta.roles是否包含角色的key值,如果包含那么就是有权限,否则无权限
    return route.meta.roles.some((role: string) => role.indexOf(roles) >= 0);
  } else {
    // 默认不设置有权限
    return true;
  }
}

export default router;
